package com.itheima.controller;

import com.itheima.pojo.Category;
import com.itheima.pojo.Result;
import com.itheima.service.CategoryService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Log4j2
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private RedisTemplate redisTemplate;



/**
 * 分类分页
 */
    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "1")Integer page,
                       @RequestParam(defaultValue = "10")Integer pageSize){
    return categoryService.page(page, pageSize);
    }

    /**
     * 分类添加
     */
    @PostMapping
    public Result add(HttpServletRequest request, @RequestBody Category category){
        return categoryService.add(request, category);
    }

    /**
     * 分类删除
     */
    @DeleteMapping
    public Result delect(String id){
        return categoryService.delect(id);
    }
    /**
     * 分类修改
     */
    @PutMapping
    public Result update(@RequestBody Category category){
        return categoryService.put(category);
    }


    /**
     * 分类下拉列表
     */
    @GetMapping("/list")
    public Result list(Integer type){
        return categoryService.list(type);

    }
}
